package easy;

public class Day15 {
    public static void main(String[] args) {
        String a = "1010";
        String b = "1011";
        System.out.println(addBinary(a, b));
    }

    public static String addBinary(String a, String b) {
        int indexA = a.length() - 1;
        int indexB = b.length() - 1;
        StringBuilder stringBuilder = new StringBuilder();
        int temp = 0;
        while (indexA >= 0 || indexB >= 0) {
            if (indexA >= 0) temp += a.charAt(indexA--) - '0';
            if (indexB >= 0) temp += b.charAt(indexB--) - '0';
            stringBuilder.append(temp % 2);
            temp >>= 1;
        }
        if (temp != 0) {
            stringBuilder.append(temp);
        }
        return stringBuilder.reverse().toString();

    }
}
